<?php
//部门
namespace app\crmindex\model;

use app\crmindex\controller\User;
use think\Db;
use weworkapi\api\datastructure\message\TextCardMessageContent;
use weworkapi\api\datastructure\message\Message;
class Dynamic extends \ShopModel
{
    protected $table = 'sh_crm_dynamic';
    protected $pk = 'dynamic_id';
    protected $autoWriteTimestamp = true;
    protected $updateTime = false;
    protected $createTime = 'create_at';
    public function DepartmentDb(){
        return Db::name('crm_dynamic');
    }
    //新增
    public function add($data){

        $CrmindexController = new \CrmindexController();
        $userId = $CrmindexController->UserId;

        $Staff = new Staff();
        $userInfo = $Staff->getInfo($userId);

        $ad['add_time'] = date('Y-m-d H:i:s');
        $ad['content'] = $data['content'];
        $ad['subregion_id'] = $data['subregion_id'];
        $ad['staff_id'] = $userId;
        $addTime = $ad['add_time'];

       // if($userInfo['is_dynamic']==0){
        //    return '账号没有使用权！';
       // }

        $addImg['dynamic_id'] =  $addAccessory['dynamic_id'] = $addGoods['dynamic_id'] = $id =  $this->insertGetId($ad);

        if($userInfo['is_dynamic_manage']==0){//如果死管理员 有置顶
            $add['is_stick'] =  isset($data['is_stick'])?$data['is_stick']:0;
        }

        if ($userInfo['is_downstream']==1){//如果是员工可以定时发送 可添加商品 附件
            $add['is_issue'] =   isset($data['is_issue'])?$data['is_issue']:0;
            if($add['is_issue']==1){$addTime = $add['add_time'] = $data['add_time'];}
            if(isset($data['goods'])&&!empty($data['goods'])){
                foreach ($data['goods'] as $goodsK=>$goodsV){
                    $addGoods['goods_id'] = $goodsV;
                    Db::name('crm_dynamic_goods')->insert($addGoods);
                }
            }
            //判断是否上传附件
            if(isset($data['accessory'])&&!empty($data['accessory'])){

                foreach ($data['accessory'] as $accessoryK=>$accessoryV){
                    $addAccessory['accessory_url'] = $accessoryV['accessory_url'];
                    $addAccessory['accessory_name'] = $accessoryV['accessory_name'];
                    Db::name('crm_dynamic_accessory')->insert($addAccessory);
                }
            }
            //判断是否上传图片
            if(isset($data['img'])&&!empty($data['img'])){

                foreach ($data['img'] as $imgK=>$imgV){
                    $addImg['img_url'] = $imgV['img_url'];
                    $addImg['img_name'] = $imgV['img_name'];
                    Db::name('crm_dynamic_img')->insert($addImg);
                }
            }
            //分享
            $add['is_share'] =  isset($data['is_share'])?$data['is_share']:0;
            //可见范围
            if(isset($data['visible_type'])){
                if($data['visible_type']==1){
                    $ad2['staff_id'] = $userId;
                    $ad2['dynamic_id'] = $id;
                    $ad2['visible_type'] = 1;
                    $ad2['add_time'] = $addTime;
                    Db::name('crm_dynamic_line')->insert($ad2);
                }elseif ($data['visible_type']==2){
                    $ad2['dynamic_id'] = $id;
                    $ad2['visible_type'] = 2;
                    $ad2['add_time'] = $addTime;
                    foreach ($data['line_staff'] as $LineV){
                        $ad2['staff_id'] = $LineV;
                        Db::name('crm_dynamic_line')->insert($ad2);
                    }

                }elseif ($data['visible_type']==3){
                    $ad2['dynamic_id'] = $id;
                    $ad2['visible_type'] = 3;
                    $ad2['add_time'] = $addTime;
                    foreach ($data['online_staff'] as $onLineV){
                        $ad2['staff_id'] = $onLineV;
                        Db::name('crm_dynamic_line')->insert($ad2);
                    }
                }
            }else{
                $ad2['add_time'] = $addTime;
                $ad2['staff_id'] = $userId;
                $ad2['dynamic_id'] = $id;
                $ad2['visible_type'] = 1;
                $ad2['is_downstream'] = 1;
                Db::name('crm_dynamic_line')->insert($ad2);
            }

        }else{
            $ad2['add_time'] = $addTime;
            $ad2['staff_id'] = $userId;
            $ad2['dynamic_id'] = $id;
            $ad2['visible_type'] = 1;
            $ad2['is_downstream'] = 1;
            Db::name('crm_dynamic_line')->insert($ad2);
        }
        //所在位置
        if(isset($data['location'])){
            $add['location'] = $data['location'];
        }
        //消息标题
        if(isset($data['title'])){
            $add['title'] = $data['title'];
        }
        //连接
        if(isset($data['content_url'])){
            $add['content_url'] = $data['content_url'];
        }
        //消息摘要
        if(isset($data['abstract'])){
            $add['abstract'] = $data['abstract'];
        }
        //动态分类
        if(isset($data['classify_id'])&&!empty($data['classify_id'])){
            $addclassify['dynamic_id'] = $id;
            if(is_array($data['classify_id'])){
                foreach ($data['classify_id'] as $classifyV){
                    $addclassify['classify_id'] = $classifyV;
                    Db::name('crm_dynamic_classify')->insert($addclassify);
                }
            }else{
                $addclassify['classify_id'] = $data['classify_id'];
                Db::name('crm_dynamic_classify')->insert($addclassify);
            }
           // $add['classify_id'] = $data['classify_id'];
        }else{
            $addclassify['dynamic_id'] = $id;
            $addclassify['classify_id'] = 0;
            Db::name('crm_dynamic_classify')->insert($addclassify);
        }

        $this->where('dynamic_id',$id)->update($add);
        $ret['dynamic_id'] = $id;
        $ret['staff_id'] = $this->tList($data['subregion_id']);

        return $ret;

    }
    //查询浏览记录接口
    function browseRecord($dynamic_id,$type = 0){

        $sql1 = Db::name('crm_dynamic_browse')->where('dynamic_id',$dynamic_id)->order('browse_time','desc')->buildSql();
        $db = Db::table($sql1.' a')->join('sh_crm_staff s','a.staff_id=s.staff_id','left');

        if($type==1){
            $data = $db->where('a.is_downstream',1)->group('a.staff_id')->field('a.*,s.staff_name,s.head_img')->select();
            foreach ($data as $k=>$v){
                $data[$k]['count'] = Db::name('crm_dynamic_browse')->where('staff_id',$v['staff_id'])->count();
            }

        }elseif ($type==0){
            $data = $db->where('a.is_downstream',0)->group('a.staff_id')->field('a.*,s.staff_name,s.head_img')->select();
            foreach ($data as $k=>$v){
                $data[$k]['count'] = Db::name('crm_dynamic_browse')->where('staff_id',$v['staff_id'])->count();
            }
        }else{
           $data1= Db::name('crm_dynamic_browse')->where('dynamic_id',$dynamic_id)->group('staff_id')->count();
           $data2 = Db::name('crm_staff')->count();
           $data['noBrowse'] = $data2-$data1;

        }
        return $data;
    }
    //查询未看列表
    function getNobrowseRecordList($dynamic_id,$type=0){
        $NOWhere = Db::name('crm_dynamic_browse')->where('dynamic_id',$dynamic_id)->where('is_downstream',$type)->column('staff_id');
        $where['staff_id'] = ['not in',$NOWhere];
        $data = Db::name('crm_staff')->where($where)->where('is_downstream',$type)->field('staff_id,staff_name')->select();
        return $data;
    }
    //浏览
    function browse($dynamic_id){
        $CrmindexController = new \CrmindexController();
        $add['staff_id'] = $CrmindexController->UserId;
        $Staff = new Staff();
        $userInfo = $Staff->getInfo($add['staff_id']);
        $add['is_downstream'] = $userInfo['is_downstream'];
        $add['dynamic_id'] = $dynamic_id;
        $add['browse_time'] = date('Y-m-d H:i:s');
        Db::name('crm_dynamic_browse')->insert($add);
    }
    //点赞
    public function praise($dynamic_id){
        $CrmindexController = new \CrmindexController();
        $userId = $CrmindexController->UserId;

        $Staff = new Staff();
        $userInfo = $Staff->getInfo($userId);
        if($userInfo['is_downstream']==0)$add['is_downstream'] = 1;
        $add['dynamic_id'] = $dynamic_id;
        $add['staff_id'] = $userId;
        $a = Db::name('crm_dynamic_praise')->where($add)->count();
        if($a>0){
            Db::name('crm_dynamic_praise')->where($add)->delete();
        }else{
            Db::name('crm_dynamic_praise')->insert($add);
        }
        $subregion_id = Db::name('crm_dynamic')->where('dynamic_id',$add['dynamic_id'])->value('subregion_id');
        $qx = $this->jurisdiction($subregion_id);
        if($qx['is_downstream_access']==0){
            $ret['count'] = Db::name('crm_dynamic_praise')->alias('a')->join('sh_crm_staff s','a.staff_id = s.staff_id','left')->where('s.is_downstream',1)->where('a.dynamic_id',$add['dynamic_id'])->count();
        }else{
            $ret['count'] =  Db::name('crm_dynamic_praise')->where('dynamic_id',$add['dynamic_id'])->count();
        }
        return $ret;
    }
    //评论
    public function comment($data){
        $CrmindexController = new \CrmindexController();
        $userId = $CrmindexController->UserId;
        $add['dynamic_id'] = $data['dynamic_id'];
        $add['staff_id'] = $userId;
        $add['pid'] =  $data['pid'];
        $add['comment'] =  $data['comment'];
        $add['comment_id'] = Db::name('crm_dynamic_comment')->insertGetId($add);
        $subregion_id = Db::name('crm_dynamic')->where('dynamic_id',$add['dynamic_id'])->value('subregion_id');
        $ret = $add;
        $crm_staff =Db::name('crm_staff')->where('staff_id', $add['staff_id'] )->field('head_img,staff_name')->find();
        $ret['staff_name'] = $crm_staff['staff_name'];
        $ret['head_img'] = $crm_staff['head_img'];
        $qx = $this->jurisdiction($subregion_id);
        if($qx['is_downstream_access']==0){
            $ret['count'] = Db::name('crm_dynamic_comment')->alias('a')->join('sh_crm_staff s','a.staff_id = s.staff_id','left')->where('s.is_downstream',1)->where('a.dynamic_id',$add['dynamic_id'])->count();
        }else{
            $ret['count'] =  Db::name('crm_dynamic_comment')->where('dynamic_id',$add['dynamic_id'])->count();
        }
        return $ret;
    }

    public function getComment($data){


        $data = Db::name('crm_dynamic_comment')->alias('a')->join('sh_crm_staff v','a.staff_id = v.staff_id')->where('dynamic_id',$data['dynamic_id'])->field('a.*,v.staff_name,v.head_img')->select();

        return $data;
    }
    //权限
    private function jurisdiction($subregion_id){
        $qx = Db::name('crm_subregion_sys')->where('subregion_id',$subregion_id)->find();
        $CrmindexController = new \CrmindexController();
        $userId = $CrmindexController->UserId;
        $Staff = new \app\crmindex\model\Staff();
        $staffInfo = $Staff->getInfo($userId);
        $ret['downstream_scope'] = 1;
        $ret['is_downstream_access'] = 1;
        if($staffInfo['is_downstream']!=1){
            //判断是否有权看下游动态
            if($qx['downstream_scope']==1){
                $ret['downstream_scope'] = 0;
            }
            ////判断是否有权看下游点赞、评论
            if($qx['is_downstream_access']==1){
                $ret['is_downstream_access'] = 0;
            }
        }
        return $ret;
    }
    //列表
    public function listDynamic($subregion_id,$classify_id=0,$params){

        $qx = $this->jurisdiction($subregion_id);
        $CrmindexController = new \CrmindexController();
        $userId = $CrmindexController->UserId;
        $page = isset($params['page'])&&!empty($params['page']) ? $params['page'] : 1;
        $pageSize = isset($params['pageSize'])&&!empty($params['pageSize']) ? $params['pageSize'] : 20;
        $where['c.subregion_id'] = $subregion_id;
        $params['search'] =  isset($params['search'])?$params['search']:'';
        $params['is_fs'] =  isset($params['is_fs'])?$params['is_fs']:0;
        $where2['content | title | abstract'] = ['like','%'.$params['search'].'%'];
        if($params['is_fs']==1){
            $where2['add_time'] = ['>',date('Y-m-d H:i:s')];
        }else{
            $where2['add_time'] = ['<',date('Y-m-d H:i:s')];
        }

        //2对部分人可见、3对部分人不可见，
        $b = Db::name('crm_dynamic_line')->alias('a')->join('sh_crm_dynamic c','a.dynamic_id = c.dynamic_id')->
        where($where)->where('a.visible_type',2)->where('a.staff_id',$userId);
        $c2 = Db::name('crm_dynamic_line')->alias('a')->join('sh_crm_dynamic c','a.dynamic_id = c.dynamic_id')->
        where($where)->where('a.visible_type',3)->where('a.staff_id',$userId);
        if($classify_id!=0){
            $b->join('sh_crm_dynamic_classify dc','a.dynamic_id = dc.dynamic_id')->where('dc.classify_id',$classify_id);
            $c2->join('sh_crm_dynamic_classify dc','a.dynamic_id = dc.dynamic_id')->where('dc.classify_id',$classify_id);
        }
        $b = $b->column('a.dynamic_id');
        $c2 = $c2->column('a.dynamic_id');

        $c = Db::name('crm_dynamic_line')->alias('a')->join('sh_crm_dynamic c','a.dynamic_id = c.dynamic_id')->
        where($where)->where('a.visible_type',3)->where('a.dynamic_id','not in',$c2)->group('a.dynamic_id');
        if($classify_id!=0){
            $c->join('sh_crm_dynamic_classify dc','a.dynamic_id = dc.dynamic_id')->where('dc.classify_id',$classify_id);
        }
        $c = $c->column('a.dynamic_id');


        $a = Db::name('crm_dynamic_line')
            ->alias('a')->join('sh_crm_dynamic c','a.dynamic_id = c.dynamic_id')
            ->where('a.visible_type',1)->where($where);
        if($classify_id!=0){
            $a->join('sh_crm_dynamic_classify dc','a.dynamic_id = dc.dynamic_id')->where('dc.classify_id',$classify_id);
        }
        $a =  $a->column('a.dynamic_id');
        //置顶消息
        //0全部动态，1上游动态，2下游动态，3包含附件动态，4自己发布动态
        $params['type'] =  isset($params['type'])?$params['type']:0;
        if($params['type']!=0){
            if($params['type']==1){
                $where2['staff.is_downstream'] = 1;
            }elseif ($params['type']==2){
                $where2['staff.is_downstream'] = 0;
            }
            elseif ($params['type']==3){
                $accessoryDynamic = Db::name('crm_dynamic_accessory')->group('dynamic_id')->column('dynamic_id');
                $where2['dynamic_id'] = ['in',$accessoryDynamic];
            }
            elseif ($params['type']==4){
                $where2['dynamic.staff_id'] = $userId;
            }
        }
        if($page==1){
            $dataStick = Db::name('crm_dynamic')->alias('dynamic')->join('sh_crm_staff staff','dynamic.staff_id=staff.staff_id')
                ->whereOr('dynamic_id','in',$c)
                ->whereOr('dynamic_id','in',$b)
                ->whereOr('dynamic_id','in',$a)
                ->where($where2)
                ->where('dynamic.is_stick',1)
                ->field('dynamic.*,staff.staff_name,staff.head_img')->order('add_time','desc')->select();
        }else{
            $dataStick=[];
        }


        $data = Db::name('crm_dynamic')->alias('dynamic')->join('sh_crm_staff staff','dynamic.staff_id=staff.staff_id')
            ->whereOr('dynamic_id','in',$c)
            ->whereOr('dynamic_id','in',$b)
            ->whereOr('dynamic_id','in',$a)
            ->where($where2)
            ->where('dynamic.is_stick',0)
            ->field('dynamic.*,staff.staff_name,staff.head_img')->order('add_time','desc');

        if($qx['downstream_scope']==0){
            $data->where('staff.is_downstream',1);
        }
        $data = $data->page($page,$pageSize)->select();
        $data = array_merge($dataStick,$data);
        $Staff = new Staff();
        $userInfo = $Staff->getInfo($userId);
        $addb['staff_id'] = $userId;
        $addb['is_downstream'] = $userInfo['is_downstream'];


        foreach ($data as $dataK=>$dataV){

            $addb['dynamic_id'] = $dataV['dynamic_id'];
            $addb['browse_time'] = date('Y-m-d H:i:s');
            Db::name('crm_dynamic_browse')->insert($addb);
           $data[$dataK]['accessory'] = Db::name('crm_dynamic_accessory')->where('dynamic_id',$dataV['dynamic_id'])->field('accessory_url,accessory_name')->select();
           $data[$dataK]['goods'] = Db::name('crm_dynamic_goods')->alias('dg')->join('sh_goods g','dg.goods_id=g.goods_id')->where('dg.dynamic_id',$dataV['dynamic_id'])->field('g.*')->select();
           $data[$dataK]['img'] = Db::name('crm_dynamic_img')->where('dynamic_id',$dataV['dynamic_id'])->field('img_url,img_name')->select();
           //查看下游评论点赞权
            if($qx['downstream_scope']==0){
                $data[$dataK]['comment'] = Db::name('crm_dynamic_comment')->alias('a')->join('sh_crm_staff s','a.staff_id=s.staff_id')->
                where('a.dynamic_id',$dataV['dynamic_id'])->where('s.is_downstream',1)->field('a.*,s.staff_name')->select();
                $data[$dataK]['praise'] = Db::name('crm_dynamic_praise')->alias('a')->join('sh_crm_staff s','a.staff_id=s.staff_id')
                    ->where('a.dynamic_id',$dataV['dynamic_id'])->where('s.is_downstream',1)->field('s.staff_id,s.staff_name')->select();
            }else{
                $data[$dataK]['comment'] = Db::name('crm_dynamic_comment')->alias('a')->join('sh_crm_staff s','a.staff_id=s.staff_id')->
                where('a.dynamic_id',$dataV['dynamic_id'])->field('a.*,s.staff_name')->select();
                $data[$dataK]['praise'] = Db::name('crm_dynamic_praise')->alias('a')->join('sh_crm_staff s','a.staff_id=s.staff_id')
                    ->where('a.dynamic_id',$dataV['dynamic_id'])->field('s.staff_id,s.staff_name')->select();
            }
            $data[$dataK]['commentCount'] = count($data[$dataK]['comment']);
            $data[$dataK]['praiseCount'] = count($data[$dataK]['praise']);
            //浏览数量
            $data[$dataK]['browseCount'] = Db::name('crm_dynamic_browse')->where('dynamic_id',$dataV['dynamic_id'])->count();
            $data[$dataK]['classify'] = Db::name('crm_dynamic_classify')->alias('a')->join('sh_crm_subregion_classify c','a.classify_id=c.classify_id','right')
                ->where('dynamic_id',$dataV['dynamic_id'])->field('c.classify_id,c.classify_name')->select();

        }

        return $data;
    }
    //置顶
    function stick($dynamic_id){
        $is_stick = Db::name('crm_dynamic')->where('dynamic_id',$dynamic_id)->value('is_stick');
        if($is_stick==0){

            Db::name('crm_dynamic')->where('dynamic_id',$dynamic_id)->update(['is_stick'=>1]);
        }else{
            Db::name('crm_dynamic')->where('dynamic_id',$dynamic_id)->update(['is_stick'=>0]);
        }
    }
    //更改分类
    function setClassify($dynamic_id,$classify_id){
        //动态分类
        Db::name('crm_dynamic_classify')->where('dynamic_id',$dynamic_id)->delete();
        if(!empty($classify_id)){
            $addclassify['dynamic_id'] = $dynamic_id;
            if(is_array($classify_id)){
                foreach ($classify_id as $classifyV){
                    $addclassify['classify_id'] = $classifyV;
                    Db::name('crm_dynamic_classify')->insert($addclassify);
                }
            }else{
                $addclassify['classify_id'] = $classify_id;
                Db::name('crm_dynamic_classify')->insert($addclassify);
            }
            // $add['classify_id'] = $data['classify_id'];
        }else{
            $addclassify['dynamic_id'] = $dynamic_id;
            $addclassify['classify_id'] = 0;
            Db::name('crm_dynamic_classify')->insert($addclassify);
        }

    }
    //设置可见范围
    function setLink($data){
        $CrmindexController = new \CrmindexController();
        $userId = $CrmindexController->UserId;
        $Staff = new Staff();
        $userInfo = $Staff->getInfo($userId);
        Db::name('crm_dynamic_line')->where('dynamic_id',$data['dynamic_id'])->delete();
        $add['add_time'] = date('Y-m-d H:i:s');
        $add['is_downstream'] = $userInfo['is_downstream']==1?0:1;
        $add['visible_type'] = $data['visible_type'];
        $add['dynamic_id'] = $data['dynamic_id'];
        if($data['visible_type']==1){
            $add['staff_id'] = $userId;
            Db::name('crm_dynamic_line')->insert($add);
        }else{
            foreach ($data['staff_id'] as $staff_id){
                $add['staff_id'] = $staff_id;
                Db::name('crm_dynamic_line')->insert($add);
            }
        }
    }
    function commentDel($comment_id){
        $where['comment_id'] =  $comment_id;
        Db::name('crm_dynamic_comment')->where($where)->delete();
     }
    function dynamicDel($dynamic_id){
         $where['dynamic_id'] =  $dynamic_id;
         Db::name('crm_dynamic')->where($where)->delete();
     }
     //附件搜索
    function searchAccessory($search=''){

        $where['accessory_name'] = ['like','%'.$search.'%'];
        $data = Db::name('crm_dynamic_accessory')->alias('a')
            ->join('sh_crm_dynamic d','a.dynamic_id=d.dynamic_id','right')
            ->join('sh_crm_staff s','d.staff_id = s.staff_id')
            ->where($where)->field('d.dynamic_id,s.staff_id,s.staff_name,d.add_time,a.accessory_url,a.accessory_name')->select();
        return $data;
    }
    //单条动态
    public function infoDynamic($dynamic_id){
        $data = Db::name('crm_dynamic')->alias('dynamic')->
        join('sh_crm_staff staff','dynamic.staff_id=staff.staff_id')->where('dynamic.dynamic_id',$dynamic_id)
            ->field('dynamic.*,staff.staff_name,staff.head_img')
            ->find();
        $qx = $this->jurisdiction($data['subregion_id']);
        $CrmindexController = new \CrmindexController();
        $userId = $CrmindexController->UserId;
            $data['accessory'] = Db::name('crm_dynamic_accessory')->where('dynamic_id',$data['dynamic_id'])->field('accessory_url,accessory_name')->select();
            $data['goods'] = Db::name('crm_dynamic_goods')->alias('dg')->join('sh_goods g','dg.goods_id=g.goods_id')->where('dg.dynamic_id',$data['dynamic_id'])->field('g.*')->select();
            $data['img'] = Db::name('crm_dynamic_img')->where('dynamic_id',$data['dynamic_id'])->field('img_url,img_name')->select();
            //查看下游评论点赞权
            if($qx['downstream_scope']==0){
                $data['comment'] = Db::name('crm_dynamic_comment')->alias('a')->join('sh_crm_staff s','a.staff_id=s.staff_id')->
                where('a.dynamic_id',$data['dynamic_id'])->where('s.is_downstream',1)->field('a.*,s.staff_name')->select();
                $data['praise'] = Db::name('crm_dynamic_praise')->alias('a')->join('sh_crm_staff s','a.staff_id=s.staff_id')
                    ->where('a.dynamic_id',$data['dynamic_id'])->where('s.is_downstream',1)->field('s.staff_id,s.staff_name')->select();
            }else{
                $data['comment'] = Db::name('crm_dynamic_comment')->alias('a')->join('sh_crm_staff s','a.staff_id=s.staff_id')->
                where('a.dynamic_id',$data['dynamic_id'])->field('a.*,s.staff_name')->select();
                $data['praise'] = Db::name('crm_dynamic_praise')->alias('a')->join('sh_crm_staff s','a.staff_id=s.staff_id')
                    ->where('a.dynamic_id',$data['dynamic_id'])->field('s.staff_id,s.staff_name')->select();
            }
            $data['commentCount'] = count($data['comment']);
            $data['praiseCount'] = count($data['praise']);
            //浏览数量
            $data['browseCount'] = Db::name('crm_dynamic_browse')->where('dynamic_id',$data['dynamic_id'])->count();
            $data['classify'] = Db::name('crm_dynamic_classify')->alias('a')->join('sh_crm_subregion_classify c','a.classify_id=c.classify_id','right')
                ->where('dynamic_id',$data['dynamic_id'])->field('c.classify_id,c.classify_name')->select();
        return $data;
    }
    //新增是消息提醒列表
    public function tList($subregion_id){
        //获取管理员列表
        $staff1 = Db::name('crm_staff')->where('is_dynamic_manage',0)->column('staff_id');
        $staff2 = Db::name('crm_subregion_remind_staff')->where('subregion_id',$subregion_id)->column('staff_id');
        $staff = array_unique(array_merge($staff1,$staff2));
        return $staff;
    }

}
